<?php

namespace App\Http\Controllers\User;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Service\User\UserService;
use App\Http\Controllers\Controller;

class RegisterController extends Controller
{
    protected $index = 'User.register';

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * 注册视图
     */
    public function register()
    {
        $title='注册';
        return view($this->index)->with('title',$title);
   }

    /**
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Laravel\Lumen\Http\Redirector|void
     * 执行注册
     */
    public function doRegister(Request $request)
    {
        $where = [];
        $where = $request->except('_token');
        $data['qq'] = $where['qq'];
        $data['name'] = $where['username'];
        $data['password'] = $where['pass'];
        $data['mobile'] = $where['phone'];
        $data['verify_code'] = $where['check'];
        $data['agent_id'] = env('AGENT');

        $user = new UserService();
        $ret = $user->register($data);

//        dd($ret);

        return $ret;

//        if($ret['code'] == 0)
//        {
//            return redirect('/login');
//        }else{
//            echo "<script>alert('{$ret['msg']}');history.back();</script>";
//        }

    }
}
